package com.example.demo.services;

import com.example.demo.entity.Users;
import com.example.demo.repository.UsersRepository;
import org.springframework.stereotype.Service;

@Service
public class UsersService {
    private final UsersRepository usersRepository;

    public UsersService(UsersRepository usersRepository) {
        this.usersRepository = usersRepository;
    }

    public int Login(String userID, String password) {
        //System.out.println("a002:2");
        if (password == null) {
            return -1;
        }
        Users list = usersRepository.userLogin(userID);
        if (list == null) {
            return -1;   //账号错误，没有数据
        }
        String getPassword = list.getLoginPassword();
        String getStatus = list.getUserStatus();
        /*System.out.println("list:" + list);
        System.out.println("pass:" + getPassword);
        System.out.println("status:" + getStatus);*/
        if (!getPassword.equals(password)) {
            return -1;  //账号密码错误
        }else if(!getStatus.equals("有效")){
            return -2;  //帐号状态无效
        }else{
            return 1;   //登录成功
        }
    }

    public String name(String userID) {
        return usersRepository.userName(userID);
    }
}
